package com.siae.controller;

import com.siae.pojo.Item;
import com.siae.pojo.vo.ItemVo;
import com.siae.pojo.vo.PageResult;
import com.siae.pojo.vo.Result;
import com.siae.service.ItemService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/item")
@Tag(name = "ItemController",description = "项目信息的操作")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("/{id}")
    public Result<Map> getItemById( @PathVariable("id") Integer id){
        return itemService.getItemById(id);
    }

    // 查询项目全部信息
    @GetMapping
    public Result<PageResult<List<Map>>> getAllItems(
            @RequestParam(name = "currentPage",defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,
            @RequestParam(name = "team",defaultValue = "0") Integer team,
            @RequestParam(name = "student",defaultValue = "0") Integer student,
            @RequestParam(name = "name",defaultValue = "") String name,
            @RequestParam(name = "type",defaultValue = "") String type,
            @RequestParam(name = "status",defaultValue = "") Integer status
    ){
        return itemService.getAllItems(currentPage,pageSize,team,student,name,type,status);
    }
    @PostMapping
    public Result addItem(@RequestBody Map dateMap){
        return itemService.addItem(dateMap);
    }
    @PutMapping
    public Result updateItem(@RequestBody Map dateMap){
        return itemService.updateItem(dateMap);
    }
    @DeleteMapping("/{id}")
    public Result deleteItem(@PathVariable("id") Integer id){
        return itemService.deleteItem(id);
    }
}
